<?php
include("db/connect.php");
$sqlselectupdate="select * from employee where emp_id='".$_POST["temp"]."'";
$queryselectupdate=mysql_query($sqlselectupdate);
$fetchselectupdate=mysql_fetch_array($queryselectupdate);
?>
<form id="fromInsert_Emp" name="fromInsert_Emp" method="post" action="Javascript:ajaxmanage(3,<?php echo $_POST["temp"]?>);">
  <p align="center">ข้อมูลลูกค้า</p>
  <table width="528" border="0">
  <tr><td>คำนำหน้าชื่อ</td><td>
          <select name="emp_title" id="emp_title"> 
            <option>โปรดเลือกคำนำหน้าชื่อ</option>
            <option value="0">นาย</option>
            <option value="1">นาง</option>
            <option value="2">นางสาว</option>
          </select>
          </td>
    </tr>
    <tr>
      <td width="178">รหัสลูกค้า</td>
      <td width="340"><input type="text" name="emp_id" id="emp_id" readonly value="<?php echo $fetchselectupdate["emp_id"]?>"/></td>
    </tr>
    <tr>
      <td>ชื่อ</td>
      <td><input name="emp_name" type="text" id="emp_name" value="<?php echo $fetchselectupdate["emp_name"]?>" /></td>
    </tr>
    <tr>
      <td>นามสกุล</td>
      <td><input name="emp_lastname" type="text" id="emp_lastname" value="<?php echo $fetchselectupdate["emp_lastname"]?>" /></td>
    </tr>
    <tr>
      <td>ที่อยู่</td>
      <td><textarea name="emp_addr" id="emp_addr" cols="45" rows="3"><?php echo $fetchselectupdate["emp_addr"]?></textarea></td>
    </tr>
    <tr>
      <td><label for="select">จังหวัด :</label></td>
      <td><select name="province_id" id="province_id">
        <?php
		$sqlprovince="select * from province order by province_name";
		$queryprovince=mysql_query($sqlprovince); 
	while($resultprovince=mysql_fetch_array($queryprovince)){
		?>
        <option value="<?php echo $resultprovince["province_id"]?>" <?php if($resultprovince["province_id"]==$fetchselectupdate["province_id"]) echo"selected"; ?>><?php echo $resultprovince["province_name"]?></option>
        >
        <?php
        }
	?>
      </select></td>
    </tr>
    <tr>
      <td><label for="select7">อำเภอ :</label></td>
      <td><div id="spaceamphur">
        <select name="amphur_id" id="amphur_id">
          <?php 
		  $sqlselectamphur="select * from amphur where province_id ='".$fetchselectupdate["province_id"]."'";	
		  $queryamphur=mysql_query($sqlselectamphur);
		  while($resultamphur=mysql_fetch_array($queryamphur)){
			  ?> <option value="<?php echo $resultamphur["amphur_id"]?>" <?php if($resultamphur["amphur_id"]==$fetchselectupdate["amphur_id"]) echo "selected"?>><?php echo $resultamphur["amphur_name"]?></option> <?php
			  }	  
		  ?>
        </select>
      </div></td>
    </tr>
    <tr>
      <td><label for="select8"> ตำบล :</label></td>
      <td><div id="spacetambol">
        <select name="tambol_id" id="tambol_id">
          <?php 
		  $sqlselecttambol="select * from tambol where amphur_id ='".$fetchselectupdate["amphur_id"]."'";	
		  $querytambol=mysql_query($sqlselecttambol);
		  while($resulttambol=mysql_fetch_array($querytambol)){
			  ?> <option value="<?php echo $resulttambol["tambol_id"]?>" <?php if($resulttambol["tambol_id"]==$fetchselectupdate["tambol_id"]) echo "selected"?>><?php echo $resulttambol["tambol_name"]?></option> <?php
			  }	  
		  ?>
        </select>
      </div></td>
    </tr>
    <tr>
      <td>รหัสไปร์ษณีย์</td>
      <td><input type="text" name="emp_postal" id="emp_postal" value="<?php echo $fetchselectupdate["emp_postal"]?>"/></td>
    </tr>
    <tr>
      <td>เบอร์โทรศัพท์</td>
      <td><input type="text" name="emp_tel" id="emp_tel" required value="<?php echo $fetchselectupdate["emp_tel"]?>"/></td>
    </tr>
    <tr>
      <td>E-mail</td>
      <td><input type="email" name="emp_mail" id="emp_mail" required value="<?php echo $fetchselectupdate["emp_mail"]?>"/></td>
    </tr>
  </table>
  <p align="center">
    <input type="submit" name="Submit" id="button" value="ตกลง" />
    <input type="reset" name="button2" id="button2" value="ยกเลิก" />
  </p>
  <p>&nbsp;</p>
</form>
<script>$(document).ready(function() {
    $("#province_id").change(function(){
		if($("#province_id").val()==1234){
			alert("โปรดเลือกจังหวัด");
			$("#amphur_id").html('');
			$("#amphur_id").html("<option value='1234'>โปรดเลือกจังหวัด</option>");
			$("#tambol_id").html('');
			$("#tambol_id").html("<option value='1234'>โปรดเลือกอำเภอ</option>");
			}
			else{
		$.ajax({
			type:"POST",
			url:"listamphur.php",
			data:"temp="+$("#province_id").val(),
			success: function(msg){
				$("#spaceamphur").html(msg);
				}
			});//ajax
			
			}//else
	});//province change
}); 
/*function amphur*/
function amphur_change(){
		$.ajax({
			type:"POST",
			url:"listtambon.php",
			data:"temp="+$("#amphur_id").val(),
			success: function(msg){
				$("#spacetambol").html(msg);
				}
			});//ajax
	}//amphurchange
	
	function submitEmp(){
	$.ajax({
			type:"POST",
			url:"insert_employee2.php",
			data:$("#fromInsert_Emp").serialize(),
			success: function(msg){
				$("#spantest").html(msg);
				}
			});//ajax
	}
	
</script>
